function set_focus(){
  var bFound = false;
  // for each form
  for (f=0; f < document.forms.length; f++)
  {
    // for each element in each form
    for(i=0; i < document.forms[f].length; i++)
    {
      // if it's not a hidden element
      if (document.forms[f][i].type != "submit")
      {
        if (document.forms[f][i].type != "hidden")
        {
          // and it's not disabled
          if (document.forms[f][i].disabled != true)
          {
            // set the focus to it
            document.forms[f][i].focus();
            var bFound = true;
          }
        }
      }
      // if found in this element, stop looking
      if (bFound == true)
        break;
    }
    // if found in this form, stop looking
    if (bFound == true)
      break;
  }
}//end set_focus

function myCustomExecCommandHandler(editor_id, elm, command, user_interface, value) {
  var linkElm, imageElm, inst;

  switch (command) {
    case "mceLink":
      inst = tinyMCE.getInstanceById(editor_id);
      linkElm = tinyMCE.getParentElement(inst.selection.getFocusElement(), "a");

      if (linkElm)
        alert("Link dialog has been overriden. Found link href: " + tinyMCE.getAttrib(linkElm, "href"));
      else
        alert("Link dialog has been overriden.");

    return true;
  }

  return false; // Pass to next handler in chain
}

function show_tree_folder(folder_id){
  id = "tree_folder_" + folder_id;

  groups = document.getElementsByTagName('ul');
  for (var i = 0; i < groups.length; i++){
    gclass = groups[i].getAttribute("class");
    if (gclass == null){
      //For IE
      gclass = groups[i].getAttribute("className");
    }
    if (gclass == "tree_group"){
      gid = groups[i].getAttribute("id");
      if (gid == id){
         Effect.toggle(gid,'blind');
      }
    }
  }
}

function switch_tab(tab){
  /*
    Switch tab colors
  */
  tab_id = "tab_" + tab;
  tabs = getElementsByClass("tab");
  for (i = 0; i < tabs.length; i ++){
    tabs[i].style.color = "#cccccc";
  }
  tab_element = document.getElementById(tab_id);
  tab_element.style.color = "#ff7700";

  /*
    Switch show/hide state of content
  */
  tab_contents = getElementsByClass("tab_content");
  for (i = 0; i < tab_contents.length; i ++){
    tab_contents[i].style.display = "none";
  }
  content_id = "content_" + tab;
  Effect.toggle(content_id,'blind');
}


function getElementsByClass(searchClass) {
  var classElements = new Array();
  var els = document.getElementsByTagName('*');
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if (pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}
